package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysLooper;
import com.ruoyi.system.service.ISysLooperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * looperController
 *
 * @author king
 * @date 2022-07-14
 */
@RestController
@RequestMapping("/system/looper")
public class SysLooperController extends BaseController
{
    @Autowired
    private ISysLooperService sysLooperService;

    /**
     * 查询looper列表
     */
    @PreAuthorize("@ss.hasPermi('system:looper:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLooper sysLooper)
    {
        startPage();
        List<SysLooper> list = sysLooperService.selectSysLooperList(sysLooper);
        return getDataTable(list);
    }

    /**
     * 导出looper列表
     */
    @PreAuthorize("@ss.hasPermi('system:looper:export')")
    @Log(title = "looper", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLooper sysLooper)
    {
        List<SysLooper> list = sysLooperService.selectSysLooperList(sysLooper);
        ExcelUtil<SysLooper> util = new ExcelUtil<SysLooper>(SysLooper.class);
        util.exportExcel(response, list, "looper数据");
    }

    /**
     * 获取looper详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:looper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysLooperService.selectSysLooperById(id));
    }

    /**
     * 新增looper
     */
    @PreAuthorize("@ss.hasPermi('system:looper:add')")
    @Log(title = "looper", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLooper sysLooper)
    {
        return toAjax(sysLooperService.insertSysLooper(sysLooper));
    }

    /**
     * 修改looper
     */
    @PreAuthorize("@ss.hasPermi('system:looper:edit')")
    @Log(title = "looper", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLooper sysLooper)
    {
        return toAjax(sysLooperService.updateSysLooper(sysLooper));
    }

    /**
     * 删除looper
     */
    @PreAuthorize("@ss.hasPermi('system:looper:remove')")
    @Log(title = "looper", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysLooperService.deleteSysLooperByIds(ids));
    }
}
